<?php
/**
 * Created by PhpStorm.
 * User: zhj
 * Date: 2019/3/21
 * Time: 11:05
 */
namespace app\index\controller;

use app\common\behavior\InitBase;

class Collection extends IndexBase
{
    private $type  =  ['城市','美食','文化','风景'];
    private $modelName =  ['City','Foods','Culture','Scenery'];
    protected $collection ;
    public function __construct()
    {
        $this->collection =  new \app\common\model\Collection();
        parent::__construct();
    }

    public function getCollection()
    {
         $user_id = session('userid');
         if(!$user_id){
             $this->error('请先登录~',url('login/index'),2);
         }
         $collection_list = $this->collection->getCollection($user_id);
         $list_info = [];
         foreach ($collection_list as $k=>$value){
             $logic = 'logic'.$this->modelName[$value['type']-1];
             $listMethod = 'get'.$this->modelName[$value['type']-1].'Info';
             $info = [];
             $info = $this->$logic->$listMethod(['id'=>$value['collection']])->toArray();
             $list_info[] = array_merge($value,$info);
         }
         $this->assign('modelName',$this->modelName);
         $this->assign('list',$list_info);
         return  $this->fetch('index');
    }
}